package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Test002 {
    //尝试独立写出服务端代码
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9832);

        while (true) {
            System.out.println("wait");
            Socket socket = serverSocket.accept();
            System.out.println("ping");

            InputStream inputStream = socket.getInputStream();
            int len;
            byte[] buf = new byte[1024];
            while ((len = inputStream.read(buf)) != -1) {
                System.out.println(new String(buf, 0, len));
            }
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("nonono".getBytes());
            socket.shutdownOutput();
            socket.close();
//            inputStream.close();
//            outputStream.close();
//            serverSocket.close();
        }


    }
}
